<?php
namespace Api\Controller;
use Org\Util\Date;
use Think\Controller;
class PlanController extends CommonController {
    function index(){
        if(IS_POST){
            $map['studentid'] = array('eq',I('studentid'));
            $data = [];
            if(I('classtags')){
                $map1['studentid'] = array('eq',I('studentid'));
                $map1['classtag'] = array('in',I('classtags'));
                $map1['_logic'] = 'OR';
                $planlist = M('plan')->where($map1)->order('create_time desc')->select();
            }else
                $planlist = M('plan')->where($map)->order('create_time desc')->select();
            foreach ($planlist as $k => $v){
                $data[$k]['id'] = $v['id'];
                $data[$k]['remark'] = $v['remark'];
                $data[$k]['time'] = date("H:i",$v['finish_time']);
                $data[$k]['day'] = date("m月d日",$v['finish_time']).lbweekday($v['finish_time']);
            }
            echo lbjson(0,'请求数据成功',$data);
        }else
            echo lbjson(1,'请求方式错误',[]);
    }

    public function searchplan()
    {
        if(IS_POST){
            $map['remark'] = array('like','%'.I('post.searchVal').'%');
            $map['studentid'] = array('eq',I('studentid'));
            $data = [];
            $planlist=[];
            if(I('classtags')){
                $map11['remark'] = array('like','%'.I('post.searchVal').'%');

                $map1['studentid'] = array('eq',I('studentid'));
                $map1['classtag'] = array('in',I('classtags'));
                $map1['_logic'] = 'OR';
                $map11['_complex'] = $map1;
                $planlist = M('plan')->where($map11)->order('create_time desc')->select();
                //echo lbjson(1,M('plan')->getLastSql(),[]);exit;
            }else
                $planlist = M('plan')->where($map)->order('create_time desc')->select();
            foreach ($planlist as $k => $v){
                $data[$k]['id'] = $v['id'];
                $data[$k]['remark'] = $v['remark'];
                $data[$k]['time'] = date("H:i",$v['finish_time']);
                $data[$k]['day'] = date("m月d日",$v['finish_time']).lbweekday($v['finish_time']);
            }
            echo lbjson(0,'请求数据成功',$data);
        }else
            echo lbjson(1,'请求方式错误',[]);
    }
   public function addplan(){
        if(IS_POST){
            $data = I('post.');
            $data['finish_time']=strtotime($data['finish_time']);
            $data['create_time'] = time();
            $tag = M('plan')->add($data);
            if($tag)
                echo lbjson(0,'添加成功',['id'=>$tag]);
            else
                echo lbjson(1,'添加失败',[]);
        }else
            echo lbjson(1,'请求方式错误',[]);
   }


}